<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/base :: commonHead(_,_)"></head>
<link rel="stylesheet" th:href="@{/js/jconfirm/jquery-confirm.min.css}">
<script th:src="@{/js/ckeditor/ckeditor.js}"></script>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside th:replace="admin/base :: commonMenu"></aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header th:replace="admin/base :: commonHeader"></header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">

                                <form class="site-form">
                                    <div class="form-group">
                                        <label for="old-password">旧密码</label>
                                        <input class="form-control" id="old-password" name="oldPassword"
                                               placeholder="输入账号的原登录密码" type="password">
                                    </div>
                                    <div class="form-group">
                                        <label for="new-password">新密码</label>
                                        <input class="form-control" id="new-password" name="newPassword"
                                               placeholder="输入新的密码" type="password">
                                    </div>
                                    <div class="form-group">
                                        <label for="confirm-password">确认新密码</label>
                                        <input class="form-control" id="confirm-password" name="newPassword1"
                                               placeholder="再次输入新的密码" type="password">
                                    </div>
                                </form>
                                <button class="btn btn-primary" id="btn-pwd" type="submit">修改密码</button>
                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </main>
        <!--End 页面主要内容-->
        </aside>
    </div>
</div>

<footer th:replace="admin/base :: commonFooter"></footer>
<!--<script th:src="@{/js/bootstrap-notify.min.js}" type="text/javascript"></script>-->
<!--<script th:src="@{/js/lightyear.js}" type="text/javascript"></script>-->
<!--<script th:src="@{/js/jconfirm/jquery-confirm.min.js}"></script>-->


<script>

    $("#btn-pwd").click(function () {
        var formObject = {};
        var formArray = $(".site-form").serializeArray();

        // 获取form表达数据
        $.each(formArray, function (i, item) {
            formObject[item.name] = item.value;
        });

        lightyear.loading('show');
        // 假设ajax提交操作
        $.ajax({
            type: "PUT",
            url: "/admin/profile/updatePassword",
            contentType: "application/json",
            dataType: "json",
            timeout: 50000,
            data: JSON.stringify(formObject),
            async: false,
            success: function (data) {
                lightyear.loading('show');
                // 假设ajax提交操作
                if (data.code === 1) {
                    setTimeout(function () {
                        lightyear.loading('hide');
                        lightyear.url("/admin/index");  // 先指定跳转链接
                        lightyear.notify(data.msg, 'success', 300);
                    }, 1e3)
                } else {
                    setTimeout(function () {
                        lightyear.loading('hide');
                        lightyear.notify(data.msg, 'danger', 100);
                    }, 1e3)
                }

            },
            error: function (err) {
                setTimeout(function () {
                    lightyear.loading('hide');
                    lightyear.notify('服务器错误，请稍后再试~', 'danger', 100);
                }, 1e3)
            }
        })
    })
</script>
</body>
</html>